package com.novel.entiy;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.novel.entiy.vo.CommentVO;
import com.novel.utils.BeanConverter;
import com.novel.utils.ConverterUtil;import com.novel.utils.DateUtils;import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author tanghao
 * @date 2022/4/18
 */
@ApiModel(value = "com-novel-entiy-Comment")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "`comment`")
public class Comment implements BeanConverter<CommentVO> {
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "")
    private Long id;

    /**
     * 评论内容
     */
    @TableField(value = "comment_content")
    @ApiModelProperty(value = "评论内容")
    private String commentContent;

    /**
     * 小说id
     */
    @TableField(value = "novel_id")
    @ApiModelProperty(value = "小说id")
    private Long novelId;

    /**
     * 评论用户id
     */
    @TableField(value = "comment_user_id")
    @ApiModelProperty(value = "评论用户id")
    private Long commentUserId;

    /**
     * 评论用户名称
     */
    @TableField(value = "comment_user_name")
    @ApiModelProperty(value = "评论用户名称")
    private String commentUserName;

    /**
     * 父评论id（0为父评论,其他为回复评论）
     */
    @TableField(value = "comment_parent_id")
    @ApiModelProperty(value = "父评论id（0为父评论,其他为回复评论）")
    private Long commentParentId;

    /**
     * 回复的评论id(可能回复评论 也可能回复评论的回复）
     */
    @TableField(value = "comment_reply_id")
    @ApiModelProperty(value = "回复的评论id(可能回复评论 也可能回复评论的回复）")
    private Long commentReplyId;

    /**
     * 回复的评论用户名称
     */
    @TableField(value = "comment_reply_user_name")
    @ApiModelProperty(value = "回复的评论用户名称")
    private String commentReplyUserName;

    /**
     * 回复的评论用户id
     */
    @TableField(value = "comment_reply_user_id")
    @ApiModelProperty(value = "回复的评论用户id")
    private Long commentReplyUserId;

    /**
     * 点赞数
     */
    @TableField(value = "comment_nums")
    @ApiModelProperty(value = "点赞数")
    private Long commentNums;

    /**
     * 0:评论 1:回复
     */
    @TableField(value = "comment_type")
    @ApiModelProperty(value = "0:评论 1:回复")
    private Integer commentType;

    /**
     * 创建时间
     */
    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    @TableField(value = "created_time",fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建时间")
    private Date createdTime;

    /**
     * 更新时间
     */
    @JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
    @TableField(value = "updated_time",fill = FieldFill.INSERT_UPDATE)
    @ApiModelProperty(value = "更新时间")
    private Date updatedTime;

    public static final String COL_ID = "id";

    public static final String COL_COMMENT_CONTENT = "comment_content";

    public static final String COL_NOVEL_ID = "novel_id";

    public static final String COL_COMMENT_USER_ID = "comment_user_id";

    public static final String COL_COMMENT_USER_NAME = "comment_user_name";

    public static final String COL_COMMENT_PARENT_ID = "comment_parent_id";

    public static final String COL_COMMENT_REPLY_ID = "comment_reply_id";

    public static final String COL_COMMENT_REPLY_USER_NAME = "comment_reply_user_name";

    public static final String COL_COMMENT_REPLY_USER_ID = "comment_reply_user_id";

    public static final String COL_COMMENT_NUMS = "comment_nums";

    public static final String COL_COMMENT_TYPE = "comment_type";

    public static final String COL_CREATED_TIME = "created_time";

    public static final String COL_UPDATED_TIME = "updated_time";

    /**
     * 转换接口方法
     *
     * @return T
     */
    @Override
    public CommentVO doForward() {
        CommentVO commentVO = new CommentVO();
        ConverterUtil.copyPropertiesIgnoreNull(this, commentVO);
        long diffMin = DateUtils.getDiffMin(commentVO.getUpdatedTime(), new Date())+1;
        if (diffMin >= 60) {
            long diffHour = DateUtils.getDiffMin(commentVO.getUpdatedTime(), new Date());
            if (diffHour >= 24) {
                return commentVO;
            }
            commentVO.setDiff(diffHour);
            commentVO.setDiffUnit("小时");
        }
        commentVO.setDiff(diffMin);
        commentVO.setDiffUnit("分钟");
        return commentVO;
    }
}